package com.ruoyi.ysVideo.domain;

import com.ruoyi.common.core.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;

/**
 * @program: class by cxf
 * @author: AbrahamBill
 * @date: 2022/9/2
 **/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ImgInfo extends BaseEntity {
    private static final long serialVersionUID = 1L;
    private Long id;
    private String deviceSerial;
    private String picUrl;
    private String myCreateTime;
    private String resUrl;
    private String tag;

    public ImgInfo(Long id, String deviceSerial, String picUrl, String myCreateTime, String resUrl, String tag) {
        this.id = id;
        this.deviceSerial = deviceSerial;
        this.picUrl = picUrl;
        this.myCreateTime = myCreateTime;
        this.resUrl = resUrl;
        this.tag = tag;
    }

    private int sum;
    public void init_sum(){
        // 结果图如果存在，就把第一个/替换为空，和picUrl统一，方便前端处理
        if(this.resUrl!=null){
            this.resUrl = this.resUrl.replaceFirst("/profile","profile");
        }else{
            this.resUrl = this.picUrl;
        }
        // 初始化sum，计算病害总量
        this.sum = 0;
        if(this.tag==null||this.tag.equals("")){
            return;
        }
        String ori = this.tag.replace("{","").replace("}","").replace(" ","");
        if(!ori.equals("")){
            List<String> lst = Arrays.asList(ori.split(","));
            lst.forEach(el->{
                this.sum+=Integer.parseInt(el.split(":")[1]);
            });
        }
    }
}
